package com.example.popup;


import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import com.example.ISelectable;

// todo refactor
public class Select {

    public static final int TYPE_RACE = 1;
    public static final int TYPE_MESSAGE_TYPE = 2;

    public static void race(final CharSequence[] races, final Activity activity, final ISelectable iSelectable) {
        if (races == null || activity == null) {
            // todo catch it
            throw new IllegalArgumentException();
        }

        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        builder.setTitle("Select race:");
        builder.setItems(races, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                iSelectable.onItemSelected(TYPE_RACE, item);
            }
        }).create().show();
    }

    public static void messageType(final CharSequence[] types, final Activity activity, final ISelectable iSelectable) {
        if (types == null || activity == null) {
            // todo catch it
            throw new IllegalArgumentException();
        }

        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        builder.setTitle("Select type:");
        builder.setItems(types, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                iSelectable.onItemSelected(TYPE_MESSAGE_TYPE, item);
            }
        }).create().show();
    }

}
